/**    
 * @{#} InvitPatientActivity.java Create on 2014年8月5日 下午9:59:18    
 *    
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin;

import java.util.HashMap;

import org.json.JSONObject;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import cn.o.app.ui.OAlert;
import cn.o.app.ui.OAlert.OAlertListener;
import cn.skinapp.R;

import com.evan.common.handler.RequestHandler;
import com.evan.common.handler.callback.HandlerCallback;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.intercept.RequestTaskIntercept;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;
import com.umeng.analytics.MobclickAgent;

public class InvitePatientFromBingliActivity extends BasicActivity {

	private EditText edit_tel;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_invite_patient_from_bingli);

		init();
		setNavTitle("创建患者账号");

		edit_tel = (EditText) findViewById(R.id.edit_tel);
	}

	@Override
	public void onClick(View view) {
		super.onClick(view);
		int id = view.getId();
		if (id == R.id.btn_create_invite) {
			String tel = CommonUtility.getText(edit_tel);
			if (CommonUtility.isNull(tel)) {
				CommonUtility.tip(activity, "请输入手机号码");
				return;
			}
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put(Constant.PARAM_API, "MR.User.Regist");
			params.put("uid", getIntent().getStringExtra(Constant.IDENTITY_KEY));
			params.put("mobile", tel);
			params.put(Constant.PARAM_TOKEN, GlobalSettings.sToken);
			RequestTaskIntercept.requestIntercept(activity,
					Constant.URL.REQUEST, new RequestHandler(activity,
							new HandlerCallback() {

								@Override
								public void callback(Object o) {
									if (!CommonUtility.isNull(o)) {
										try {
											JSONObject object = (JSONObject) o;
											if (CommonUtility
													.response200(object)) {
												OAlert alert = new OAlert(
														activity);
												alert.setOK("确认");
												alert.setCancel("取消");
												alert.setTitle("患者邀请信息已发送");
												alert.show();
												alert.setListener(new OAlertListener() {

													@Override
													public boolean onOK(
															OAlert alert) {
														finish();
														return false;
													}

													@Override
													public boolean onCancel(
															OAlert alert) {
														return false;
													}
												});
											} else {
												CommonUtility.tip(
														activity,
														object.getString(Constant.JSON_PARAM_RESULTMESSAGE));
											}
										} catch (Exception e) {
											e.printStackTrace();
										}
									}
								}
							}), params);
		}
	}

/*	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}*/
}
